package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.tabhost.TabHostSpec;
import com.aplink.generic.xmlparser.PageCollectionParser;
import com.aplink.generic.xmlparser.XmlPaserUtil;

public class TabHostFormat {
	public static final String BACK_GROUNDCOLOR = "backgroundColor";
	public static final String DISPLAY = "display";
	public static final String START_PAGE_INDEX = "startpageindex";

	public static TabHostSpec parse(final Node node) {
		final TabHostSpec switchSpec = new TabHostSpec();
		if (node.hasAttributes()) {
			String value = XmlPaserUtil.getAttrValue(node, DISPLAY);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setDisplay(value);
			}

			value = XmlPaserUtil.getAttrValue(node, START_PAGE_INDEX);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setStartTab(Integer.parseInt(value));
			}

			value = XmlPaserUtil.getAttrValue(node, BACK_GROUNDCOLOR);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setBackgroundColor(value);
			}
		}
		switchSpec.setPageCollection(PageCollectionParser.parse(node));
		return switchSpec;
	}
}
